package com.ganwenlong.collections;

import java.util.PriorityQueue;

public class ToDoList extends PriorityQueue<ToDoList.ToDoItem> {

	private static final long serialVersionUID = 72780918325723973L;

	public void add(String item, char primary, int secondary) { 
		super.add(new ToDoList.ToDoItem(item, primary, secondary)); 
	}
	public static void main(String[] args) { 
		ToDoList list = new ToDoList(); 
		list.add("Empty trash", 'C', 4); 
		list.add("Feed dog", 'A', 2); 
		list.add("Feed bird", 'B', 7); 
		list.add("Mow lawn", 'C', 1); 
		list.add("Water lawn", 'A', 1); 
		list.add("Feed cat", 'B', 1); 
		while(!list.isEmpty()) { 
			System.out.println(list.remove()); 
		}
	}
	
	
	static class ToDoItem implements Comparable<ToDoItem> { 
		
		private char primary; 
		private int secondary; 
		private String item; 
		
		public ToDoItem(String item, char primary, int secondary) { 
			this.primary = primary; 
			this.secondary = secondary; 
			this.item = item; 
		}
		
		@Override
		public int compareTo(ToDoItem o) { 
			if(this.primary > o.primary) { 
				return 1; 
			} 
			if(this.primary == o.primary) { 
				if(this.secondary > o.secondary) { 
					return 1; 
				} else if(this.secondary == o.secondary) { 
					return 0; 
				}
			} 
			return -1; 
		} 
		public String toString() { 
			return Character.toString(this.primary) +this.secondary + ":" + this.item; 
		}
	} 
	
}
